package cn.lbwfree.day3_25;

import java.util.Scanner;

/**
 * @date:2020年3月25日
 * @author:lbwfree
 */
public class ReturnGetNum_error {
	public static void main(String[] args) {
		Scanner inScanner = new Scanner(System.in);
		int m =inScanner.nextInt();
		int n =inScanner.nextInt();
		int[][] arrays = new int[m][n];
		for (int i = 0; i < m; i++) {
			for (int j = 0; j < n; j++) {
				arrays[i][j]=inScanner.nextInt();
			}
		}
		//最外圈
		ReturnGetNumPrint(arrays, 0, 0, 0);
	}
	public static void ReturnGetNumPrint(int[][] arrays, int m, int n, int sum) {
		
		//首竖行
		for (int i = m; i < arrays.length-m; i++) {
			if(i==0&&n==0)
			{
				//保证最后一位没有" "
				System.out.print(arrays[0][0]);
				sum++;
			}else {
				System.out.print(" "+arrays[i][n]);
				sum++;
			}
		}
		if(sum>=arrays.length*arrays[0].length)
		{
			return;
		}
		//最后横行
		for (int i = n+1; i < arrays[0].length-n-1; i++) {
			System.out.print(" "+arrays[arrays.length-m-1][i]);
			sum++;
		}
		if(sum>=arrays.length*arrays[0].length)
		{
			return;
		}
		//最后竖行
		for (int i = arrays.length-m-1; i>m; i--) {
			System.out.print(" "+arrays[i][arrays[0].length-n-1]);
			sum++;
		}
		if(sum>=arrays.length*arrays[0].length)
		{
			return;
		}
		//首横行
		for (int i = arrays[0].length-n-1; i>n; i--) {
			System.out.print(" "+arrays[m][i]);
			sum++;
		}
		if(sum>=arrays.length*arrays[0].length)
		{
			return;
		}
		n++;
		m++;
		ReturnGetNumPrint(arrays, m, n, sum);
	}

}
